package edu.csl.study.coreserver2.feign;

import edu.csl.study.coreserver2.vo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 如果直接实现MyFeignClient，那么无法获取到异常信息，所以要这么处理
 */
@Component
public class MyFeignClientFallback implements FallbackFactory<MyFeignClient> {
    Logger logger = LoggerFactory.getLogger(MyFeignClientFallback.class);
    @Override
    public MyFeignClient create(Throwable throwable) {

        return new MyFeignClient(){

            @Override
            public String hello() {
                logger.error(MyFeignClient.class.getSimpleName()+"#hello服务出现异常："+throwable.getMessage(),throwable);
                return "hello的降级服务！！！1";
            }

            @Override
            public String updateUser3(String userName, String password) {
                return "updateUser3的降级服务！！！1";
            }

            @Override
            public String updateUser2(User user) {
                return "updateUser2的降级服务！！！1";
            }
        };
    }
}
